define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'money/tixian/index' + location.search,
                    add_url: 'money/tixian/add',
                    edit_url: 'money/tixian/edit',
                    multi_url: 'money/tixian/multi',
                    import_url: 'money/tixian/import',
                    table: 'user_money_tx',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'getmoney', title: __('Getmoney'), operate:'BETWEEN'},
                        {field: 'bankname', title: __('Bankname'), operate: 'LIKE'},
                        {field: 'banknumber', title: __('Banknumber'), operate: 'LIKE'},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,   buttons:[
                                {
                                    name: 'ajax',
                                    text: __(''),
                                    title: __('打款成功'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'money/tixian/txsuccess',
                                    confirm: '确认已经打款！',
                                    success: function (data, ret) {
                                        //return false;
                                        location.reload();
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        return false;
                                    },
                                },
                                {
                                    name: 'ajax',
                                    text: __(''),
                                    title: __('打款驳回'),
                                    classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                    icon: 'fa fa-close',
                                    url: 'money/tixian/txbohui',
                                    confirm: '确认驳回打款！',
                                    success: function (data, ret) {
                                        location.reload();

                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        return false;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status == 0){
                                            return true;
                                        }else {
                                            return false;
                                        }

                                    }

                                }
                            ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
